<template>
  <view class="product-card">
    <image class="product-image" :src="product.image" mode="aspectFill" />
    <view class="product-info">
      <text class="product-name">{{ product.name }}</text>
      <view class="product-stats">
        <text class="rating">⭐ {{ product.rating }}</text>
        <text class="sales">已售{{ product.sales }}</text>
      </view>
      <view class="product-price">
        <text class="current-price">¥{{ product.price }}</text>
        <text class="original-price">¥{{ product.originalPrice }}</text>
      </view>
    </view>
    <view class="product-actions">
      <view class="add-cart-btn" @click="handleAddToCart">
        🛒 加入购物车
      </view>
      <view class="buy-now-btn" @click="handleBuyNow">
        立即购买
      </view>
    </view>
  </view>
</template>

<script setup>
defineProps({
  product: {
    type: Object,
    required: true
  }
})

const emit = defineEmits(['addToCart', 'buy'])

const handleAddToCart = () => {
  emit('addToCart', props.product.id)
}

const handleBuyNow = () => {
  emit('buy', props.product.id)
}
</script>

<style scoped>
.product-card {
  background: #fff;
  border-radius: 20rpx;
  margin-bottom: 20rpx;
  overflow: hidden;
  box-shadow: 0 4rpx 20rpx rgba(0, 0, 0, 0.1);
}
.product-image {
  width: 100%;
  height: 300rpx;
}
.product-info {
  padding: 20rpx;
}
.product-name {
  font-size: 28rpx;
  font-weight: bold;
  color: #333;
  margin-bottom: 15rpx;
  display: block;
  line-height: 1.4;
}
.product-stats {
  display: flex;
  align-items: center;
  margin-bottom: 15rpx;
}
.rating {
  font-size: 22rpx;
  color: #ff6b35;
  margin-right: 20rpx;
}
.sales {
  font-size: 22rpx;
  color: #999;
}
.product-price {
  display: flex;
  align-items: center;
  margin-bottom: 20rpx;
}
.current-price {
  font-size: 32rpx;
  font-weight: bold;
  color: #ff6b35;
  margin-right: 15rpx;
}
.original-price {
  font-size: 24rpx;
  color: #999;
  text-decoration: line-through;
}
.product-actions {
  display: flex;
  gap: 15rpx;
  padding: 0 20rpx 20rpx;
}
.add-cart-btn, .buy-now-btn {
  flex: 1;
  text-align: center;
  padding: 20rpx;
  border-radius: 40rpx;
  font-size: 26rpx;
  font-weight: bold;
}
.add-cart-btn {
  background: #fff;
  color: #ff6b35;
  border: 2rpx solid #ff6b35;
}
.buy-now-btn {
  background: #ff6b35;
  color: #fff;
}
</style>
